package com.jss.lanouhn.fristapp.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jss.lanouhn.fristapp.Interface.OnItemClickLister;
import com.jss.lanouhn.fristapp.R;
import com.jss.lanouhn.fristapp.modles.CategoryStrategyTop;
import com.squareup.picasso.Picasso;

/**
 * Created by lanouhn on 16/8/25.
 */
public class CategoryStrategyTopAdapter extends RecyclerView.Adapter<CategoryStrategyTopAdapter.TopViewHolder>{

    private Context mContext;
    private CategoryStrategyTop categoryStrategyTop;
    private OnItemClickLister onItemClickLister;

    public void setOnItemClickLister(OnItemClickLister onItemClickLister){
        this.onItemClickLister=onItemClickLister;
    }

    public CategoryStrategyTopAdapter(Context mContext, CategoryStrategyTop categoryStrategyTop) {
        this.mContext = mContext;
        this.categoryStrategyTop = categoryStrategyTop;
    }

    @Override
    public TopViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_category_strategy_lanmu,null);
        TopViewHolder holder=new TopViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final TopViewHolder holder, int position) {
        CategoryStrategyTop.DataBean.ColumnsBean bean=categoryStrategyTop.getData().getColumns().get(position);
        Picasso.with(mContext).load(bean.getBanner_image_url()).into(holder.imageView);
        holder.tv_title.setText(bean.getTitle());
        holder.tv_times.setText(bean.getSubtitle());
        holder.tv_name.setText(bean.getAuthor());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int pos=holder.getLayoutPosition();
                onItemClickLister.onItemClick(holder.itemView,pos);
            }
        });
    }

    @Override
    public int getItemCount() {
        return categoryStrategyTop.getData().getColumns().size();
    }

    public class TopViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView;
        private TextView tv_title,tv_times,tv_name;

        public TopViewHolder(View itemView) {
            super(itemView);
            imageView= (ImageView) itemView.findViewById(R.id.riv_item_strategy);
            tv_title= (TextView) itemView.findViewById(R.id.tv_item_strategy);
            tv_times= (TextView) itemView.findViewById(R.id.tv1_item_strategy);
            tv_name = (TextView) itemView.findViewById(R.id.tv2_item_strategy);


        }
    }
}
